<?php
class ReportViewModel extends ViewModel{
	public $viewFields = array(	
			'report'=>array('*' ,'_as'=>'r' ,'_type'=>'LEFT'),	
			'products'=>array('products_name '=>'products_name','uid'=>'puid','_as'=>'p','_on'=>'r.products_id=p.products_id','_type'=>'LEFT'),
			'membership' =>array('name','_as'=>'m','_on'=>'r.uid=m.uid','_type'=>'LEFT'),
	
	);
	
	
	//獲取所有信息
	public function getAll($where,$limit,$order){
		  return $this->where($where)->limit($limit)->order($order)->select();
		//echo $this->getLastSql();die;
	}
	//獲取一條信息
	public function getOne($where){
		return $this->where($where)->find();
	}
	
	//获取同一个投诉的所有记录
	public function getOneAll($where){
		$result =  $this->where($where)->order('r.report_id asc')->select();
		foreach($result as $key=>$val){
			if($val['to_uid']!=0){
				$toname = M('membership')->where(array('uid'=>$val['to_uid']))->field('name')->find();
				$result[$key]['to_name'] = $toname['name'];
			}else{
				$result[$key]['to_name'] = 0;
			}
		}
		return $result;
	}
	
}